import requests
import json

# 创建部门请求的url
create_org_url = "https://qyapi.weixin.qq.com/cgi-bin/department/create"
# 有效token
token = "6o2IwU45eHnraRnUXHHiz9OnvuPa0rGLJaCT2PoqYKUG5IbjjVaaEav8kJN7s86z8LP3J5lWVafnhAP6kWEtE3dq1sGRHJN0vBBsv6Jzs0witW7QrZzxy7OiS_jaVhOAsJB8rSOLJqIKTpaZbUDReTzQ8i44qqyZWD8upEkT5enP1njmpFy0ChBC55W7Mfix6rMBP-lm2iMUWpJh1Entdg"
# url中的参数
my_params = {
    "access_token": token
}
# post请求的请求体
json_data = {
   "name": "测试部门202305070001",
   "parentid": 1
}
# json传参
rep = requests.post(url=create_org_url, params=my_params, json=json_data)
print(rep.json())



# del_org_url = "https://qyapi.weixin.qq.com/cgi-bin/department/delete"
# my_params = {
#     "access_token": token,
#     "id": 1042
# }
# rep = requests.get(url=del_org_url, params=my_params)
# print(rep.json())



import requests

url = "https://qyapi.weixin.qq.com/cgi-bin/department/create"

querystring = {"access_token":"6o2IwU45eHnraRnUXHHiz9OnvuPa0rGLJaCT2PoqYKUG5IbjjVaaEav8kJN7s86z8LP3J5lWVafnhAP6kWEtE3dq1sGRHJN0vBBsv6Jzs0witW7QrZzxy7OiS_jaVhOAsJB8rSOLJqIKTpaZbUDReTzQ8i44qqyZWD8upEkT5enP1njmpFy0ChBC55W7Mfix6rMBP"}

payload = "{\r\n   \"name\": \"测试部门202305070001\",\r\n   \"parentid\": 1\r\n}"
headers = {
    'cache-control': "no-cache",
    'postman-token': "ff1921b6-2ead-1305-680a-5640a0fcc42f"
    }

response = requests.request("POST", url, data=payload, headers=headers, params=querystring)

print(response.text)